// pages/detail/index.js
const WxParse = require('../../wxParse/wxParse.js');

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		info: null
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.data.id = options.id;
		this.onPullDownRefresh();
	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		wx.$model.home.postDetail({
			id: this.options.id
		}).then((res) => {
			this.setData({
				info: res
			}, () => {
				WxParse.wxParse('article', 'html', res.content, this, 32);
				wx.setNavigationBarTitle({
					title: res.title
				})
			});
		});
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		const query = "id=" + this.data.id + "&store_id=" + wx.$getStoreId();
		return {
			title: this.data.info.title,
			path: "pages/detail/index?" + query,
			query: query,
			imageUrl: this.data.info.cover
		};
	},

	/**
	 * 用户点击右上角分享朋友圈
	 */
	onShareTimeline: function () {
		return this.onShareAppMessage();
	},
})